<?php
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
require_once ROOT_PATH . '/plugins/PlugInFactoryException.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillGroup.php';

$baseURL = './CentralController.php?skillMatrixcode=SkillMatrix'; 

$skillGroup = $records;

$date = date("Y-m-d");

	$action = "EditGroup";
	$title = "Update group";
?>
<script type="text/javascript" src="../../scripts/archive.js"></script>
<?php include ROOT_PATH."/lib/common/calendar.php"; ?>
<script type="text/javascript">

function returnAdd() {
		
		location.href = '<?php echo $baseURL;?>&action=ViewAddQuestion&surveyid=<?php echo $records['skill_group_id'];?>';
}
function returnDelete() {
		var check = false;
		with (document.frmQuestion) {
			for (var i=0; i < elements.length; i++) {
				if ((elements[i].type == 'checkbox') && (elements[i].checked == true)){
					check = true;
					break;
				}
			}

			if (check) {
					document.frmQuestion.action= "<?php echo $_SERVER['PHP_SELF']; ?>?surveycode=Surveys&action=DeleteQuestions";
					document.frmQuestion.submit();				
			} else {
				alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
			}
		}
	}
	
function addSave() {
	if(validate()==true)
		document.frmSurveys.submit();
	else
		return false;
}

function addOption() {
		oLayer = document.getElementById("addAdminLayer").style.display = 'block';
}
function saveSkillExpertise() {
	if(validateOption())
	     document.frmOptionAdmins.submit();
	else
		return false;
}

function validateOption() {
	var errFlag=false;
	var option = document.getElementById('skill_expertise_name').value;
	if(option.length ==0){
		alert(" Skill expertise can not be null!");
	}else{
		errFlag = true;
	}
	return errFlag;
}

function removeSkillExpertise() {
		var check = false;
		
		with (document.frmOptionAdmins) {
			for (var i=0; i < elements.length; i++) {
				if ((elements[i].type == 'checkbox') && (elements[i].checked == true) && (elements[i].id == 'chkID')){
					check = true;
					break;
				}
			}

			if (check) {
				var flag=confirm("Are you sure you would like to delete these records?");				
				if(flag){
					document.frmOptionAdmins.action= "<?php echo $_SERVER['PHP_SELF']; ?>?skillMatrixcode=SkillMatrix&action=DeleteSkillExpertise";
					document.frmOptionAdmins.submit();
				}else{
					return false;
				}
			} else {
				alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
			}
		}
}


function checkAll(field)
{
	if(document.frmOptionAdmins.expertise.checked == false){
		for (i = 0; i < field.length; i++)
			field[i].checked = false ;
	}else{
		for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}
	
}

function validate() {
	var skillgroupname = document.getElementById('skill_group_name').value;
	var skillgrouptype = document.getElementById('skill_group_type').value;
	
	errFlag=false;
	errors = new Array();
	if(skillgroupname.length ==0){
		errors[errors.length]= "Skill group name can not be null!";
		errFlag=true;
	}
	if(!skillgrouptype){
		errors[errors.length]= "You have to select at least 1 skill group type";
		errFlag=true;
	}
	if (errFlag) {
		errStr="<?php echo $lang_Common_EncounteredTheFollowingProblems; ?>\n";
		for (i in errors) {
			errStr+=" - "+errors[i]+"\n";
		}
		alert(errStr);
		return false;
	}
	return true;
}

//YAHOO.OrangeHRM.container.init();
/*
YAHOO.util.Event.addListener($("frmSurveys"), "submit", viewProjectReport);
*/


</script>

<h2>
<?php echo $title; ?>
<hr/>
</h2>
<div id="status"></div>
<?php if (isset($_GET['message'])) {

		$expString  = $_GET['message'];
?>
		<font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php echo $expString; ?>
		</font>
<?php }	?>
<form name="frmSurveys" id="frmSurveys" method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>?skillMatrixcode=SkillMatrix&action=<?php echo $action; ?>">
<input type="hidden" name=skill_group_id value="<?php echo $records['skill_group_id']; ?>" >
<table border="0" cellpadding="2" cellspacing="0">
	<thead>
		<tr>
			<th class="tableTopLeft"></th>
	    	<th class="tableTopMiddle" ></th>
	    	<th class="tableTopMiddle" ></th>
			<th class="tableTopRight"></th>
		</tr>
	</thead>
	<tbody>
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo "Group Name"; ?></td>			
			<td >
				<input type="text" name ="skill_group_name" id ="skill_group_name" value="<?php echo $records['skill_group_name'];  ?>"/>				
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo "Group type"; ?></td>			
			<td >
				<select name="skill_group_type[]" id="skill_group_type" multiple>		
				
					<?php if(in_array(1,explode(",",$records['skill_group_type']))){ ?>					
						<option selected value="1">Developer</option>						
					<?php }else{ ?>
						<option value="1">Developer</option>						
					<?php } ?>
					
					<?php if(in_array(2,explode(",",$records['skill_group_type']))){ ?>					
						<option selected value="2">QA</option>						
					<?php }else{ ?>
						<option value="2">QA</option>						
					<?php } ?>	
				</select>
								
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ></td>
			<td >
				<input type="image"  onclick="return addSave();" name="btnSave" alt="Save"
					   src="../../themes/beyondT/pictures/btn_save.gif" />
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
		
	</tbody>
	<tfoot>
	  	<tr>
			<td class="tableBottomLeft"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomRight"></td>
		</tr>
  	</tfoot>
</table>
</form>

<form name="frmOptionAdmins" id="frmOptionAdmins" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?skillMatrixcode=SkillMatrix&action=AddSkillExpertise">
<input type="hidden" id="skill_expertise_group_id" name="skill_expertise_group_id" value="<?php echo $records['skill_group_id']; ?>"/>
<table border="0" cellpadding="5" cellspacing="0">
	<thead>
		<tr>
			<th class="tableTopLeft"></th>
	    	<th class="tableTopMiddle" ></th>
	    	<th class="tableTopMiddle" width="15"> </th>
	    	<th class="tableTopMiddle" width="5"></th>
	    	<th class="tableTopMiddle"></th>
			<th class="tableTopRight"></th>
		</tr>
	</thead>
	<tbody>		
		<tr>
			<td class="tableMiddleLeft"></td>			
			<td ><h3>Skill expertise</h3>
		<?php $skillExpertises = SkillGroup::getSkillExpertise($records['skill_group_id']);
				if(count($skillExpertises)>0) {	?>
      	<div >
		<table width="250" class="simpleList" >
			<tr >
       			<td align="center" style="border-bottom: 1px solid #000">
       				<input type='checkbox' class='checkbox' name='expertise' id='expertise' onClick="checkAll(document.frmOptionAdmins.chkID)"  ></td>
		 		<td style="border-bottom: 1px solid #000"><span style="font-weight:bold;">Skill expertise name</span></td>		 		
			</tr>			
			<?php
				$odd = false;
				foreach ($skillExpertises as $skillExpertise) {
	 	 	 		$cssClass = ($odd) ? 'even' : 'odd';
	 	 	 		$odd = !$odd;
	 		?>
    		<tr>
       			<td class="<?php echo $cssClass?>" align="center">
       				<input type='checkbox' class='checkbox' name='chkID[]' id='chkID'
       					value='<?php echo $skillExpertise->getId();?>'></td>
		 		<td class="<?php echo $cssClass?>"><?php echo $skillExpertise->getSkillExpertiseName(); ?></td>		 		
			</tr>
		 	<?php
		 		}
		  	?>
 		</table>
		</div>
		 	<?php
			 }
		  	?>

			</br>
            <div align="left">
	            <img onClick="addOption()"
	            	onMouseOut="this.src='../../themes/beyondT/pictures/btn_add.gif';"
	            	onMouseOver="this.src='../../themes/beyondT/pictures/btn_add_02.gif';"
	            	src="../../themes/beyondT/pictures/btn_add.gif">
	        <?php
	        	if (!empty($skillExpertises)) {
			?>
				<img
					onClick="removeSkillExpertise()"
				    src="../../themes/beyondT/pictures/btn_delete.gif"
					onMouseOut="this.src='../../themes/beyondT/pictures/btn_delete.gif';"
					onMouseOver="this.src='../../themes/beyondT/pictures/btn_delete_02.gif';">
			<?php
				}
	        ?>
            </div>
       
			<div id ="addAdminLayer" style="display:none;height:20px;">
		    	<label for="projAdminName">New skill expertise</label>
	               	<input type="text"  name="skill_expertise_name" id="skill_expertise_name" value="" >             	                 
	               
	            	<img onClick="return saveSkillExpertise();"
	            		style="margin-top:10px;"
	            		onMouseOut="this.src='../../themes/beyondT/icons/assign.gif';"
	            		onMouseOver="this.src='../../themes/beyondT/icons/assign_o.gif';"
	            		src="../../themes/beyondT/icons/assign.gif">
			</div>
     

			</td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td class="tableMiddleRight"></td>
		</tr>
		
		
	  
	</tbody>
	<tfoot>
	  	<tr>
			<td class="tableBottomLeft"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomRight"></td>
		</tr>
  	</tfoot>
</table>
 </form>
